import Vue from 'vue'
import App from './App.vue'
import router from './router'

Vue.config.productionTip = false

import './assets/style/erp/index.css'
import './assets/style/erp/common.css'
import ElementUI from 'element-ui'
Vue.use(ElementUI,{size: 'mini'})

import store from './store/index';
let instance = null;
function render(props) {
  console.log("子应用render的参数", props)
  if (props){

  }
  instance = new Vue({
    router,
    store,
    render: h => h(App),
  }).$mount('#app');
}
if (!window.__POWERED_BY_QIANKUN__) {render();}

export async function bootstrap(props) {
  store.commit('setBaseProps',props);
}
export async function mount(props) {
  store.commit('setBaseProps',props);
  render(props)
  props.onGlobalStateChange((state) => {
    console.log("app1 mount state",state)
    //设置compo 子应用读取router 设置 组件名称
    let route=router.getRoutes().find(item => (state.activeMenu.appCode+item.path)===state.activeMenu.path);
    if (route){
      let compo=JSON.parse(JSON.stringify(route.meta.compo));
      console.log("get compo",compo);
      state.activeMenu.compo=compo;
    }
    store.commit('setGlobalState',state);
    store.commit('addViewIncludes',state.activeMenu.compo);
  }, true)
}
export async function unmount() {
  instance.$destroy();
}
// 增加 update 钩子以便主应用手动更新微应用
export async function update(props) {
  store.commit('setBaseProps',props);
  console.log("update props",props);
}




